home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / MATH / PI / PI.ZIP / MAIN.PAS < prev    next >
Pascal/Delphi Source File  |  1996-06-17  |  3KB  |  119 lines

  1. unit main;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ExtCtrls, StdCtrls, Buttons, ComCtrls;
  8.  
  9. const
  10.   // Change this value to get more digits
  11.   PI_LIMIT = 2500;
  12.  
  13. type
  14.   TPiForm = class(TForm)
  15.     CalculatingNameLabel: TLabel;
  16.     PiProgressBar: TProgressBar;
  17.     CloseBitBtn: TBitBtn;
  18.     AbortBitBtn: TBitBtn;
  19.     StartNameLabel: TLabel;
  20.     ProcessNameLabel: TLabel;
  21.     CalculatingLabel: TLabel;
  22.     Start18Label: TLabel;
  23.     FinishTimeLabel: TLabel;
  24.     OkBitBtn: TBitBtn;
  25.     PiTimer: TTimer;
  26.     Label1: TLabel;
  27.     Start57Label: TLabel;
  28.     Label3: TLabel;
  29.     Start239Label: TLabel;
  30.     Label2: TLabel;
  31.     StartPILabel: TLabel;
  32.     procedure CloseBitBtnClick(Sender: TObject);
  33.     procedure AbortBitBtnClick(Sender: TObject);
  34.     procedure OkBitBtnClick(Sender: TObject);
  35.     procedure FormCreate(Sender: TObject);
  36.     procedure PiTimerTimer(Sender: TObject);
  37.   private
  38.     { Private declarations }
  39.   public
  40.     { Public declarations }
  41.   end;
  42.  
  43. var
  44.   PiForm: TPiForm;
  45.  
  46. implementation
  47.  
  48. uses pidata, arctan;
  49.  
  50. {$R *.DFM}
  51.  
  52. procedure TPiForm.CloseBitBtnClick(Sender: TObject);
  53. begin
  54.   Close;
  55. end;
  56.  
  57. procedure TPiForm.AbortBitBtnClick(Sender: TObject);
  58. begin
  59.   PiDataModule.cancel_operation:= True;
  60. end;
  61.  
  62. procedure TPiForm.OkBitBtnClick(Sender: TObject);
  63. var
  64.   calculate_pi: TCalculatePi;
  65. begin
  66.   // Construct a Pi class
  67.   calculate_pi.Create(PI_LIMIT);
  68.   // Set the maximum limit of the progress bar
  69.   PiProgressBar.Max:= PI_LIMIT;
  70.   // Calculate the arctangent of 1/18
  71.   CalculatingLabel.Caption:= 'ArcTan 1/18';
  72.   Start18Label.Caption:= DateTimeToStr(Now);
  73.   Application.ProcessMessages;
  74.   calculate_pi.ArcTan(18);
  75.   // Calculate the arctangent of 1/57
  76.   CalculatingLabel.Caption:= 'ArcTan 1/57';
  77.   Start57Label.Caption:= DateTimeToStr(Now);
  78.   Application.ProcessMessages;
  79.   calculate_pi.ArcTan(57);
  80.   // Calculate the arctangent of 1/239
  81.   CalculatingLabel.Caption:= 'ArcTan 1/239';
  82.   Start239Label.Caption:= DateTimeToStr(Now);
  83.   Application.ProcessMessages;
  84.   calculate_pi.ArcTan(239);
  85.   // And then sum it all up
  86.   CalculatingLabel.Caption:= 'Computing PI';
  87.   StartPILabel.Caption:= DateTimeToStr(Now);
  88.   Application.ProcessMessages;
  89.   calculate_pi.Sum;
  90.   // And tidy up now that we have finished
  91.   CalculatingLabel.Caption:= 'Finished';
  92.   PiProgressBar.Position:= 0;
  93.   PiDataModule.start_position:= 0;
  94.   FinishTimeLabel.Caption:= DateTimeToStr(Now);
  95.   Application.ProcessMessages;
  96.   // Could someone tell my why I get an exception when I un-comment the
  97.   // following line. I would have assumed that the Free was necessary?
  98. //  calculate_pi.Free;
  99. end;
  100.  
  101. procedure TPiForm.FormCreate(Sender: TObject);
  102. begin
  103.   CalculatingLabel.Caption:= '';
  104.   Start18Label.Caption:= '';
  105.   Start57Label.Caption:= '';
  106.   Start239Label.Caption:= '';
  107.   StartPILabel.Caption:= '';
  108.   FinishTimeLabel.Caption:= '';
  109. end;
  110.  
  111. procedure TPiForm.PiTimerTimer(Sender: TObject);
  112. begin
  113.   PiProgressBar.Position:= PiDataModule.start_position;
  114.   Application.ProcessMessages;
  115. end;
  116.  
  117. end.
  118.  
  119.